<template>
  <el-dialog
    v-bind="$attrs"
    v-on="$listeners"
    @open="onOpen"
    @close="onClose"
    title="审批"
    :visible.sync="show"
    append-to-body
  >
    <el-form
      ref="elForm"
      :model="formData"
      :rules="rules"
      size="small"
      label-width="100px"
    >
      <el-form-item label="是否通过" prop="approveState">
        <el-radio-group v-model="formData.approveState" size="medium">
          <el-radio
            v-for="(item, index) in approveStateOptions"
            :key="index"
            :label="item.value"
            >{{ item.label }}</el-radio
          >
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="close" size="mini">取消</el-button>
      <el-button type="primary" size="mini" @click="handleConfirm"
        >确定</el-button
      >
    </div>
  </el-dialog>
</template>
<script>
import { completeVisitPlan } from "@/api/visit/visit";
export default {
  inheritAttrs: false,
  components: {},
  props: [],
  data() {
    return {
      show: false,
      formData: {
        approveState: 1,
        visitPlanId: "",
      },
      rules: {
        approveState: [
          {
            required: true,
            message: "是否通过不能为空",
            trigger: "change",
          },
        ],
     
      },
      approveStateOptions: [
        {
          label: "通过",
          value: 2,
        },
        {
          label: "不通过",
          value: 3,
        },
      ],
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    onOpen() {},
    showDialog(id) {
      this.show = true;
      this.formData.visitPlanId = id;
    },
    onClose() {
      this.$refs["elForm"].resetFields();
    },
    close() {
      this.show = false
      this.$emit("update:visible", false);
    },
    handleConfirm() {
      this.$refs["elForm"].validate((valid) => {
        if (!valid) return;
        completeVisitPlan(this.formData).then((res) => {
          this.$message({
            message: "操作成功",
            type: "success",
          });
          this.$emit("success");
        });

        this.close();
      });
    },
  },
};
</script>
<style></style>
